package com.aind.book.service.service;

import com.aind.book.dao.BookMapper;
import com.aind.book.model.Book;
import com.aind.book.model.BookExample;
import com.aind.book.service.BookService;
import com.aind.category.model.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by lpeng on 2017/2/24.
 */
@Service(value = "aaaaaavvvv")
public class BookServiceImpl implements BookService {

    @Autowired
    private BookMapper bookMapper;

    /**
     * 通过CategoryId 查找所有的书
     * @return
     */
    public List<Book> getBookListByCategoryId(Long categoryId) {
        BookExample bookExample = new BookExample();
        bookExample.createCriteria().andCategoryIdEqualTo(categoryId);
        return bookMapper.selectByExamplePager(bookExample);
    }

    /**
     * 通过bookId进行查询
     * @param bookId
     * @return
     */
    public Book getBookByBookId(Long bookId) {
        return bookMapper.selectByPrimaryKey(bookId);
    }
}
